
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Vuex · Aivin开发笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Aivin">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-local-video/video-js.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../styles/website.css">
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="vue-router.html" />
    
    
    <link rel="prev" href="vueJS.html" />
    

    
        <link rel="shortcut icon" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    个人信息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="友情链接.html">
            
                <a href="友情链接.html">
            
                    
                    友情链接
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="js.html">
            
                <a href="js.html">
            
                    
                    web前端
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="html5.html">
            
                <a href="html5.html">
            
                    
                    html5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="js.html">
            
                <a href="js.html">
            
                    
                    js
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="css.html">
            
                <a href="css.html">
            
                    
                    css
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="JSX.html">
            
                <a href="JSX.html">
            
                    
                    JSX
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="CommonJS.html">
            
                <a href="CommonJS.html">
            
                    
                    CommonJS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="ES6.html">
            
                <a href="ES6.html">
            
                    
                    ES6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="mockjs.html">
            
                <a href="mockjs.html">
            
                    
                    mockjs
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="ESLint.html">
            
                <a href="ESLint.html">
            
                    
                    ESLint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="alias.html">
            
                <a href="alias.html">
            
                    
                    alias
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="vueJS.html">
            
                <a href="vueJS.html">
            
                    
                    vueJS
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.11" data-path="Vuex.html">
            
                <a href="Vuex.html">
            
                    
                    Vuex
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="vue-router.html">
            
                <a href="vue-router.html">
            
                    
                    vue-router
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.13" data-path="vue-i18n.html">
            
                <a href="vue-i18n.html">
            
                    
                    vue-i18n
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.14" data-path="element.html">
            
                <a href="element.html">
            
                    
                    element
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.15" data-path="iview.html">
            
                <a href="iview.html">
            
                    
                    iview
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.16" data-path="test.html">
            
                <a href="test.html">
            
                    
                    test
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >Vuex</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#vuex"><b>1. </b>Vuex</a></li><ul><li><span class="title-icon "></span><a href="#&#x6838;&#x5FC3;&#x6982;&#x5FF5;"><b>1.1. </b>&#x6838;&#x5FC3;&#x6982;&#x5FF5;</a></li><ul><li><span class="title-icon "></span><a href="#state"><b>1.1.1. </b>State</a></li><li><span class="title-icon "></span><a href="#getter"><b>1.1.2. </b>Getter</a></li><li><span class="title-icon "></span><a href="#mutation"><b>1.1.3. </b>Mutation</a></li><li><span class="title-icon "></span><a href="#action"><b>1.1.4. </b>Action</a></li><li><span class="title-icon "></span><a href="#module"><b>1.1.5. </b>Module</a></li></ul><li><span class="title-icon "></span><a href="#&#x5185;&#x7F6E;&#x51FD;&#x6570;"><b>1.2. </b>&#x5185;&#x7F6E;&#x51FD;&#x6570;</a></li><ul><li><span class="title-icon "></span><a href="#mapstate"><b>1.2.1. </b>mapState</a></li><li><span class="title-icon "></span><a href="#mapgetters"><b>1.2.2. </b>mapGetters</a></li><li><span class="title-icon "></span><a href="#mapactions"><b>1.2.3. </b>mapActions</a></li><li><span class="title-icon "></span><a href="#mapmutations"><b>1.2.4. </b>mapMutations</a></li></ul><li><span class="title-icon "></span><a href="#&#x5185;&#x7F6E;&#x63D2;&#x4EF6;"><b>1.3. </b>&#x5185;&#x7F6E;&#x63D2;&#x4EF6;</a></li><ul><li><span class="title-icon "></span><a href="#logger"><b>1.3.1. </b>logger</a></li></ul><li><span class="title-icon "></span><a href="#&#x5E38;&#x7528;api"><b>1.4. </b>&#x5E38;&#x7528;API</a></li><ul><li><span class="title-icon "></span><a href="#storedispatch"><b>1.4.1. </b>$store.dispatch</a></li><li><span class="title-icon "></span><a href="#commitsetroles-dataroles"><b>1.4.2. </b>commit(&apos;SET_ROLES&apos;, data.roles)</a></li></ul></ul></ul></div><a href="#vuex" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="vuex"><a name="vuex" class="anchor-navigation-ex-anchor" href="#vuex"><i class="fa fa-link" aria-hidden="true"></i></a>1. Vuex</h1>
<p><a href="https://vuex.vuejs.org/zh/" target="_blank">Vuex</a> &#x662F;&#x4E00;&#x4E2A;&#x4E13;&#x4E3A; Vue.js &#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x5F00;&#x53D1;&#x7684;&#x72B6;&#x6001;&#x7BA1;&#x7406;&#x6A21;&#x5F0F;&#x3002;&#x5B83;&#x91C7;&#x7528;&#x96C6;&#x4E2D;&#x5F0F;&#x5B58;&#x50A8;&#x7BA1;&#x7406;&#x5E94;&#x7528;&#x7684;&#x6240;&#x6709;&#x7EC4;&#x4EF6;&#x7684;&#x72B6;&#x6001;.
&#x9002;&#x5408;&#x5F00;&#x53D1;&#x5927;&#x578B;&#x5355;&#x9875;&#x5E94;&#x7528;</p>
<p><a href="https://blog.csdn.net/mjzhang1993/article/details/78321903" target="_blank">https://blog.csdn.net/mjzhang1993/article/details/78321903</a></p>
<pre><code class="lang-xml">npm install vuex --save
import Vuex from &apos;vuex&apos;
Vue.use(Vuex)

new Vue({
       el: &apos;#app&apos;,
       store, // &#x5C06; store &#x5B9E;&#x4F8B;&#x4ECE;&#x6839;&#x7EC4;&#x4EF6;&#x4E2D;&#x2018;&#x6CE8;&#x5165;&#x2019;&#x5230;&#x6BCF;&#x4E00;&#x4E2A;&#x5B50;&#x7EC4;&#x4EF6;&#x4E2D;&#xFF0C;&#x5B50;&#x7EC4;&#x4EF6;&#x901A;&#x8FC7; `this.$store` &#x8C03;&#x7528;
       template: &apos;<span class="hljs-tag">&lt;<span class="hljs-name">app</span>/&gt;</span>&apos;,
       components: { App }
    });
</code></pre>
<h2 id="&#x6838;&#x5FC3;&#x6982;&#x5FF5;"><a name="&#x6838;&#x5FC3;&#x6982;&#x5FF5;" class="anchor-navigation-ex-anchor" href="#&#x6838;&#x5FC3;&#x6982;&#x5FF5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. &#x6838;&#x5FC3;&#x6982;&#x5FF5;</h2>
<h3 id="state"><a name="state" class="anchor-navigation-ex-anchor" href="#state"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.1. State</h3>
<pre><code class="lang-xml">&#x91CC;&#x9762;&#x88C5;&#x4E86;n&#x4E2A;&#x4F60;&#x9700;&#x8981;&#x7528;&#x5230;&#x7684;&#x53D8;&#x91CF;&#x3002; count , msg ...
&#x4E00;&#x822C;&#x9700;&#x8981;&#x5728;&#x4F7F;&#x7528;&#x7684;&#x65F6;&#x5019;&#x5728;&#x8DDF;&#x8282;&#x70B9;&#x6CE8;&#x5165;store&#x5BF9;&#x8C61;&#xFF0C;&#x540E;&#x671F;&#x5C31;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;this.$store.state222&#x76F4;&#x63A5;&#x83B7;&#x53D6;&#x72B6;&#x6001;
</code></pre>
<h3 id="getter"><a name="getter" class="anchor-navigation-ex-anchor" href="#getter"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.2. Getter</h3>
<pre><code class="lang-xml">&#x82E5;&#x662F;&#x5BF9;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x5904;&#x7406;&#x8F93;&#x51FA;&#xFF0C;&#x6BD4;&#x5982;&#x6570;&#x636E;&#x8981;&#x8FC7;&#x6EE4;&#xFF0C;&#x4E00;&#x822C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5199;&#x5230;computed&#x4E2D;&#x3002;
&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x8BA4;&#x4E3A;&#xFF0C;getters &#x662F;store&#x7684;&#x8BA1;&#x7B97;&#x5C5E;&#x6027;&#x3002; &#x7C7B;&#x4F3C; computed &#x3002;
&#x6240;&#x4EE5; getter &#x7684;&#x8FD4;&#x56DE;&#x503C;&#x4F1A;&#x6839;&#x636E;&#x5B83;&#x7684;&#x4F9D;&#x8D56;&#x88AB;&#x7F13;&#x5B58;&#x8D77;&#x6765;&#xFF0C;&#x4E14;&#x53EA;&#x6709;&#x5F53;&#x5B83;&#x7684;&#x4F9D;&#x8D56;&#x503C;&#x53D1;&#x751F;&#x4E86;&#x6539;&#x53D8;&#x624D;&#x4F1A;&#x88AB;&#x91CD;&#x65B0;&#x8BA1;&#x7B97;&#x3002;

1&#x3001; &#x62BD;&#x53D6;&#x591A;&#x4E2A;&#x7EC4;&#x4EF6;&#x7684;&#x516C;&#x5171;&#x5C5E;&#x6027;&#xFF0C;&#x65B9;&#x4FBF;&#x83B7;&#x53D6; &#x3002;
2 &#x3001;&#x6709;&#x4E9B;&#x72B6;&#x6001;&#x9700;&#x8981;&#x505A;&#x4E8C;&#x6B21;&#x5904;&#x7406;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;getters&#x3002;
state &#x4E2D;&#x4E00;&#x822C;&#x5B58;&#x653E;&#x7684;&#x90FD;&#x662F;&#x6BD4;&#x8F83;&#x539F;&#x59CB;&#x7684;&#x6570;&#x636E;&#xFF0C;
&#x6211;&#x4EEC;&#x7684;&#x5E94;&#x7528;&#x4E2D;&#x4F7F;&#x7528;&#x7684;&#x53EF;&#x80FD;&#x4F1A;&#x662F;&#x8FD9;&#x4E9B;&#x539F;&#x59CB;&#x7684;&#x6570;&#x636E;&#x7ECF;&#x8FC7;&#x8BA1;&#x7B97;&#x540E;&#x7684;&#x6570;&#x636E;&#xFF0C;
&#x8FD9;&#x65F6;&#x5019;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728; &#x7EC4;&#x4EF6;&#x7684;&#x8BA1;&#x7B97;&#x5C5E;&#x6027;&#x4E2D;&#x64CD;&#x4F5C; &#x3002;
</code></pre>
<h3 id="mutation"><a name="mutation" class="anchor-navigation-ex-anchor" href="#mutation"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.3. Mutation</h3>
<pre><code class="lang-xml">Vuex&#x4E2D; &#x771F;&#x6B63;&#x4FEE;&#x6539; store &#x72B6;&#x6001;&#x7684; &#x552F;&#x4E00;&#x65B9;&#x6CD5;&#x5C31;&#x662F;mutation &#x3002; &#x53EA;&#x6709;&#x5728;&#x8FD9;&#x91CC;&#x624D;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x771F;&#x6B63;&#x7684;&#x72B6;&#x6001;&#x66F4;&#x6539;
mutation &#x51FD;&#x6570;&#x5FC5;&#x987B;&#x662F;&#x540C;&#x6B65;&#x7684;
</code></pre>
<h3 id="action"><a name="action" class="anchor-navigation-ex-anchor" href="#action"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.4. Action</h3>
<p>&#x5728;actions&#x4E2D;&#x5F02;&#x6B65;&#x63D0;&#x4EA4; mutation&#x3002; &#x8BA9; mutation&#x53BB;&#x540C;&#x6B65;&#x5730;&#x4FEE;&#x6539;&#x6570;&#x636E; &#x3002;
Action &#x63D0;&#x4EA4;&#x7684;&#x662F; mutation&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x76F4;&#x63A5;&#x53D8;&#x66F4;&#x72B6;&#x6001;&#x3002;</p>
<h3 id="module"><a name="module" class="anchor-navigation-ex-anchor" href="#module"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.5. Module</h3>
<p>Vuex &#x5141;&#x8BB8;&#x6211;&#x4EEC;&#x5C06; store &#x5206;&#x5272;&#x6210;&#x6A21;&#x5757;&#xFF08;module&#xFF09;&#x3002;&#x6BCF;&#x4E2A;&#x6A21;&#x5757;&#x62E5;&#x6709;&#x81EA;&#x5DF1;&#x7684; state&#x3001;mutation&#x3001;action&#x3001;getter&#x3001;&#x751A;&#x81F3;&#x662F;&#x5D4C;&#x5957;&#x5B50;&#x6A21;&#x5757;
const moduleA = {
    state: { ... },
    mutations: { ... },
    actions: { ... },
    getters: { ... }
  }</p>
<p>  const moduleB = {
    state: { ... },
    mutations: { ... },
    actions: { ... }
  }</p>
<h4 id="&#x6A21;&#x5757;&#x6DFB;&#x52A0;&#x547D;&#x540D;&#x7A7A;&#x95F4;"><a name="&#x6A21;&#x5757;&#x6DFB;&#x52A0;&#x547D;&#x540D;&#x7A7A;&#x95F4;" class="anchor-navigation-ex-anchor" href="#&#x6A21;&#x5757;&#x6DFB;&#x52A0;&#x547D;&#x540D;&#x7A7A;&#x95F4;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6A21;&#x5757;&#x6DFB;&#x52A0;&#x547D;&#x540D;&#x7A7A;&#x95F4;</h4>
<p>const moduleA = {
       namespaced: true, // &#x6DFB;&#x52A0;&#x547D;&#x540D;&#x7A7A;&#x95F4;
       state: {
           test: &apos;abc&apos;
       },
       ...
   }</p>
<pre><code> upperTest: &apos;moduleA/upperTest&apos; // &#x8FD9;&#x91CC;&#x7684;&#x5F15;&#x7528;&#x8981;&#x52A0;&#x4E0A;&#x6A21;&#x5757;&#x540D;
</code></pre><h2 id="&#x5185;&#x7F6E;&#x51FD;&#x6570;"><a name="&#x5185;&#x7F6E;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#&#x5185;&#x7F6E;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. &#x5185;&#x7F6E;&#x51FD;&#x6570;</h2>
<h3 id="mapstate"><a name="mapstate" class="anchor-navigation-ex-anchor" href="#mapstate"><i class="fa fa-link" aria-hidden="true"></i></a>1.2.1. mapState</h3>
<p>&#x5C06;state&#x6620;&#x5C04;&#x5230;&#x8BA1;&#x7B97;&#x5C5E;&#x6027;&#x4E2D; &#x3002;
&#x4E3A;&#x4E86;&#x89E3;&#x51B3; &#x7EC4;&#x4EF6;&#x5728;&#x83B7;&#x53D6;&#x591A;&#x4E2A;&#x72B6;&#x6001;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x9891;&#x7E41;&#x58F0;&#x660E;&#x4E3A;&#x8BA1;&#x7B97;&#x5C5E;&#x6027; &#x6709;&#x4E9B;&#x91CD;&#x590D;&#x548C;&#x5197;&#x4F59;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; mapState &#x8F85;&#x52A9;&#x51FD;&#x6570;&#x5E2E;&#x52A9;&#x751F;&#x6210;&#x8BA1;&#x7B97;&#x5C5E;&#x6027;</p>
<h3 id="mapgetters"><a name="mapgetters" class="anchor-navigation-ex-anchor" href="#mapgetters"><i class="fa fa-link" aria-hidden="true"></i></a>1.2.2. mapGetters</h3>
<p>&#x5C06; store &#x4E2D;&#x7684; getter &#x6620;&#x5C04;&#x5230;&#x5C40;&#x90E8;&#x8BA1;&#x7B97;&#x5C5E;&#x6027;</p>
<h3 id="mapactions"><a name="mapactions" class="anchor-navigation-ex-anchor" href="#mapactions"><i class="fa fa-link" aria-hidden="true"></i></a>1.2.3. mapActions</h3>
<p>&#x7528;&#x4E8E;&#x5C06; actions &#x6620;&#x5C04;&#x5230;&#x7EC4;&#x4EF6;&#x4E2D;</p>
<h3 id="mapmutations"><a name="mapmutations" class="anchor-navigation-ex-anchor" href="#mapmutations"><i class="fa fa-link" aria-hidden="true"></i></a>1.2.4. mapMutations</h3>
<p>&#x53EF;&#x4EE5;&#x8282;&#x7EA6;&#x4EE3;&#x7801;&#xFF0C;&#x4F7F;&#x4EE3;&#x7801;&#x66F4;&#x52A0;&#x7B80;&#x6D01;&#xFF0C;&#x4ED6;&#x5C06;&#x4F1A;&#x5728;&#x7EC4;&#x4EF6;&#x7684; methods &#x5C5E;&#x6027;&#x4E2D;&#x5B8C;&#x6210;&#x6620;&#x5C04;</p>
<h2 id="&#x5185;&#x7F6E;&#x63D2;&#x4EF6;"><a name="&#x5185;&#x7F6E;&#x63D2;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#&#x5185;&#x7F6E;&#x63D2;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. &#x5185;&#x7F6E;&#x63D2;&#x4EF6;</h2>
<h3 id="logger"><a name="logger" class="anchor-navigation-ex-anchor" href="#logger"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.1. logger</h3>
<p>plugins: [createLogger()]</p>
<h2 id="&#x5E38;&#x7528;api"><a name="&#x5E38;&#x7528;api" class="anchor-navigation-ex-anchor" href="#&#x5E38;&#x7528;api"><i class="fa fa-link" aria-hidden="true"></i></a>1.4. &#x5E38;&#x7528;API</h2>
<h3 id="storedispatch"><a name="storedispatch" class="anchor-navigation-ex-anchor" href="#storedispatch"><i class="fa fa-link" aria-hidden="true"></i></a>1.4.1. $store.dispatch</h3>
<p>&#x5728;&#x5176;&#x4ED6;&#x5730;&#x65B9;&#x901A;&#x8FC7;action &#x63D0;&#x4EA4; mutation</p>
<pre><code class="lang-xml">this.$store.dispatch(&apos;mutations&#x65B9;&#x6CD5;&#x540D;&apos;,&#x503C;)
</code></pre>
<h3 id="commitsetroles-dataroles"><a name="commitsetroles-dataroles" class="anchor-navigation-ex-anchor" href="#commitsetroles-dataroles"><i class="fa fa-link" aria-hidden="true"></i></a>1.4.2. commit(&apos;SET_ROLES&apos;, data.roles)</h3>
<p>&#x5728;action&#x4E2D;&#x63D0;&#x4EA4; mutation</p>
<footer class="page-footer"><span class="copyright">&#x65E0;&#x7248;&#x6743; &#x53EF;&#x4EE5;&#x65E0;&#x9650;&#x5236;&#x4F7F;&#x7528;&#xFF01; all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x66F4;&#x65B0;&#x65F6;&#x95F4;&#xFF1A;
2018-10-26 10:48:47
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="vueJS.html" class="navigation navigation-prev " aria-label="Previous page: vueJS">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="vue-router.html" class="navigation navigation-next " aria-label="Next page: vue-router">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Vuex","level":"1.3.11","depth":2,"next":{"title":"vue-router","level":"1.3.12","depth":2,"path":"chinese/web/vue-router.md","ref":"chinese/web/vue-router.md","articles":[]},"previous":{"title":"vueJS","level":"1.3.10","depth":2,"path":"chinese/web/vueJS.md","ref":"chinese/web/vueJS.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","search-plus","todo","anchor-navigation-ex","copy-code-button","fontsettings","tbfed-pagefooter","donate","local-video","splitter","favicon","theme-comscore","local-video"],"styles":{"website":"styles/website.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"无版权 可以无限制使用！","modify_label":"该文件更新时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"todo":{},"splitter":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"donate":{"alipay":"http://oyru0ayig.bkt.clouddn.com/201803011956_osChina_支付宝收款码.png","alipayText":"支付宝打赏","button":"打赏","title":"","wechat":"http://oyru0ayig.bkt.clouddn.com/201803011956_osChina_微信收款码.png","wechatText":"微信打赏"},"fontsettings":{"family":"sans","size":2,"theme":"sepia"},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"favicon":{"shortcut":"assets/images/favicon.ico","bookmark":"assets/images/favicon.ico"},"theme-comscore":{},"local-video":{},"copy-code-button":{},"sharing":{"all":["facebook","google","twitter","weibo","instapaper"],"facebook":true,"google":false,"instapaper":false,"twitter":true,"vk":false,"weibo":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"search-plus":{}},"theme":"default","author":"Aivin","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Aivin开发笔记","language":"zh-hans","gitbook":"*","description":"Aivin开发笔记"},"file":{"path":"chinese/web/Vuex.md","mtime":"2018-10-26T02:48:47.979Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-04-12T07:42:16.699Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-local-video/video.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

